﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Sales
{
    public partial class SystemSet : Form
    {
        public SystemSet()
        {
            InitializeComponent();
            GetSystemInfo();
        }

        private static SystemSet systemSet = null;


        public static SystemSet CreateInstance()
        {
            if (null == systemSet)
            {
                systemSet = new SystemSet();
            }
            return systemSet;
        }




        private void gbtnSet1_Click(object sender, EventArgs e)
        {
            string type = "";

            if (this.rdxsType1.Checked)
            {
                type = "1";
            }


            else if (this.rdxsType2.Checked)
            {
                type = "2";
            }
            else if (this.rdxsType3.Checked)
            {
                type = "3";
            }
            else if (this.rdxsType4.Checked)
            {
                type = "4";
            }
            else if (this.rdxsType5.Checked)
            {
                type = "5";
            }



            SetSystemInfo("XSSJ", type);
        }

        /// <summary>
        /// 保存(修改) 系统设置信息
        /// </summary>
        /// <param name="name">上传数据名称</param>
        /// <param name="type">上传数据类型</param>
        private void SetSystemInfo(string name, string type)
        {
            XmlDocument doc = new XmlDocument();
            string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\config.xml";
            doc.Load(path);    //加载Xml文件  
            XmlElement rootElem = doc.DocumentElement;   //获取根节点  
            XmlNodeList personNodes = rootElem.GetElementsByTagName("UploadInfo"); //获取PrintInfo 子节点集合  
            foreach (XmlNode node in personNodes)
            {
                XmlElement xe = (XmlElement)node;//将子节点类型转换为XmlElement类型
                if (xe.GetAttribute("Name") == name)
                {
                    xe.SetAttribute("Type", type.ToString());
                }
            }
            doc.Save("config.xml");
        }

        private void GetSystemInfo()
        {

            XmlDocument doc = new XmlDocument();
            string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + @"\config.xml";
            doc.Load(path);    //加载Xml文件  
            XmlElement rootElem = doc.DocumentElement;   //获取根节点  

            XmlNodeList personNodes = rootElem.GetElementsByTagName("UploadInfo"); //获取PrintInfo 子节点集合  

            foreach (XmlNode node in personNodes)
            {
                XmlElement xe = (XmlElement)node;//将子节点类型转换为XmlElement类型

                string Name = xe.GetAttribute("Name");

                string type = xe.GetAttribute("Type");

                if (Name == "XSSJ")
                {
                    if (type == "1")
                    {
                        this.rdxsType1.Checked = true;
                    }
                    else if (type == "2")
                    {
                        this.rdxsType2.Checked = true;
                    }
                    else if (type == "3")
                    {
                        this.rdxsType3.Checked = true;
                    }
                    else if (type == "4")
                    {
                        this.rdxsType4.Checked = true;
                    }
                    else if (type == "5")
                    {
                        this.rdxsType5.Checked = true;
                    }
                }
                else if (Name == "YYYDA")
                {
                    if (type == "1")
                    {
                        this.rdyyyType1.Checked = true;
                    }
                    else if (type == "2")
                    {
                        this.rdyyyType2.Checked = true;
                    }
                    else if (type == "3")
                    {
                        this.rdyyyType3.Checked = true;
                    }
                    else if (type == "4")
                    {
                        this.rdyyyType4.Checked = true;
                    }
                    else if (type == "5")
                    {
                        this.rdyyyType5.Checked = true;
                    }
                }
                else if (Name == "SPDA")
                {
                    if (type == "1")
                    {
                        this.rdspType1.Checked = true;
                    }
                    else if (type == "2")
                    {
                        this.rdspType2.Checked = true;
                    }
                    else if (type == "3")
                    {
                        this.rdspType3.Checked = true;
                    }
                    else if (type == "4")
                    {
                        this.rdspType4.Checked = true;
                    }
                    else if (type == "5")
                    {
                        this.rdspType5.Checked = true;
                    }
                }


            }

        }

        private void gbtnSet2_Click(object sender, EventArgs e)
        {
            string type = "";

            if (this.rdyyyType1.Checked)
            {
                type = "1";
            }


            else if (this.rdyyyType2.Checked)
            {
                type = "2";
            }
            else if (this.rdyyyType3.Checked)
            {
                type = "3";
            }
            else if (this.rdyyyType4.Checked)
            {
                type = "4";
            }
            else if (this.rdyyyType5.Checked)
            {
                type = "5";
            }



            SetSystemInfo("YYYDA", type);
        }

        private void gbtnSet3_Click(object sender, EventArgs e)
        {
            string type = "";

            if (this.rdspType1.Checked)
            {
                type = "1";
            }


            else if (this.rdspType2.Checked)
            {
                type = "2";
            }
            else if (this.rdspType3.Checked)
            {
                type = "3";
            }
            else if (this.rdspType4.Checked)
            {
                type = "4";
            }
            else if (this.rdspType5.Checked)
            {
                type = "5";
            }



            SetSystemInfo("SPDA", type);
        }


    }
}
